// problem statement:
// http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=22&page=show_problem&problem=1995

#include <iostream>
#include <vector>


using namespace std;

int main()
{
	long long n = 0; 
	while (cin >> n)
	{
                if (n == 0) break;
		vector<long long> people;
		for (int i = 0; i < n; ++i)
		{
			long long cur = 0; 
			cin >> cur; 
			people.push_back(cur);	
		}

		long long track = 0; 
		long long res = 0;
		for (int i = 0; i < people.size(); ++i)
		{
			res += track > 0 ? track : -track; 
			track += people[i];
		}
		cout << res << endl;
	}
	return 0;
}